Write-Host "清理 VitePress 缓存并重启..." -ForegroundColor Green

# 设置当前目录
Set-Location $PSScriptRoot

try {
    # 删除缓存目录
    if (Test-Path ".vitepress\cache") {
        Write-Host "正在删除缓存目录..." -ForegroundColor Yellow
        Remove-Item -Recurse -Force ".vitepress\cache" -ErrorAction Stop
        Write-Host "缓存目录删除成功" -ForegroundColor Green
    }

    # 删除构建目录
    if (Test-Path ".vitepress\dist") {
        Write-Host "正在删除构建目录..." -ForegroundColor Yellow
        Remove-Item -Recurse -Force ".vitepress\dist" -ErrorAction Stop
        Write-Host "构建目录删除成功" -ForegroundColor Green
    }

    # 检查并安装依赖
    if (-not (Test-Path "node_modules")) {
        Write-Host "正在安装依赖..." -ForegroundColor Yellow
        pnpm install
    }

    Write-Host "启动 VitePress 开发服务器..." -ForegroundColor Green
    pnpm run docs:dev

} catch {
    Write-Host "错误: $($_.Exception.Message)" -ForegroundColor Red
    Write-Host "请尝试以管理员权限运行此脚本" -ForegroundColor Yellow
    Read-Host "按回车键退出"
}
